By Amin Sabbagh
Student ID: 18055392
EthOS Reference Number: 64001
Intro | Linear Regression Models | Further Insight | Data Preprocessing Intro | Data Preprocessing Continuous | Data Preprocessing Insights
Pandas: Used to extract data from Excel into dataframes
Plotly Express: Used to create interactive data visualizations.
import pandas as pd
import plotly.express as px
# Specify the sheet name from which to read data
file_name = "COL.xlsx"
sheet_name = 'Sheet1'
# Read data from Excel file into a DataFrame
df_lines = pd.read_excel(file_name, sheet_name)
# copy the data
dfn = df_lines.copy()
#The min-max approach (often called normalization)
for column in dfn:
if pd.api.types.is_numeric_dtype(dfn[column]):
dfn[column] = (dfn[column] - dfn[column].min()) / (dfn[column].max() - dfn[column].min())
# View normalized data
display(dfn)
| Unnamed: 0 | Date | CPI | Food Inflation | Resturants Inflation | Rental Price | House Price | Motor Fuel Price | Gas inflation | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 0.000000 | 2016 JAN | 0.010989 | 0.018018 | 0.314286 | 0.320755 | 0.627329 | 0.256560 | 0.155860 |
| 1 | 0.010526 | 2016 FEB | 0.010989 | 0.036036 | 0.307143 | 0.320755 | 0.621118 | 0.256560 | 0.155860 |
| 2 | 0.021053 | 2016 MAR | 0.032967 | 0.009009 | 0.321429 | 0.320755 | 0.664596 | 0.228863 | 0.155860 |
| 3 | 0.031579 | 2016 APR | 0.021978 | 0.022523 | 0.335714 | 0.320755 | 0.633540 | 0.253644 | 0.147756 |
| 4 | 0.042105 | 2016 MAY | 0.021978 | 0.009009 | 0.342857 | 0.301887 | 0.639752 | 0.263848 | 0.151496 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 91 | 0.957895 | 2023 AUG | 0.637363 | 0.747748 | 0.814286 | 0.886792 | 0.118012 | 0.123907 | 0.203865 |
| 92 | 0.968421 | 2023 SEP | 0.637363 | 0.684685 | 0.835714 | 0.905660 | 0.055901 | 0.221574 | 0.203865 |
| 93 | 0.978947 | 2023 OCT | 0.461538 | 0.590090 | 0.814286 | 0.981132 | 0.062112 | 0.252187 | 0.000000 |
| 94 | 0.989474 | 2023 NOV | 0.406593 | 0.549550 | 0.771429 | 1.000000 | 0.000000 | 0.208455 | 0.000000 |
| 95 | 1.000000 | 2023 DEC | 0.406593 | 0.495495 | 0.735714 | 1.000000 | 0.055901 | 0.205539 | 0.000000 |
96 rows × 9 columns
# Specify the sheet name from which to read data
file_name = "Bars_Insights.xlsx"
sheet_name = '1'
# Read data from Excel file into a DataFrame
df_food = pd.read_excel(file_name, sheet_name)
# Plot
fig = px.bar(df_food, x='Class', y='Percentage', color='Spending less on food shopping and essentials', barmode='stack', title='Food & Essentials',
color_discrete_map={'No': px.colors.sequential.BuGn[3],
'Yes': px.colors.sequential.BuGn[4]},
hover_data={'Class': True, 'Spending less on food shopping and essentials': True})
fig.show()
fig = px.line(title='Food Inflation Overtime')
# Add Food trace with green color
fig.add_scatter(x=dfn['Date'], y=dfn['Food Inflation'], mode='lines', name='Food', line=dict(color='green'))
# Add CPI trace with blue color
fig.add_scatter(x=dfn['Date'], y=dfn['CPI'], mode='lines', name='CPI', line=dict(color='blue'))
fig.show()
fig = px.line(title='Resturant Inflation overtime')
# Add Food trace with green color
fig.add_scatter(x=dfn['Date'], y=dfn['Resturants Inflation'], mode='lines', name='Resturants', line=dict(color='green'))
# Add CPI trace with blue color
fig.add_scatter(x=dfn['Date'], y=dfn['CPI'], mode='lines', name='CPI', line=dict(color='blue'))
fig.show()
# Specify the sheet name from which to read data
file_name = "Bars_Insights.xlsx"
sheet_name = '4'
# Read data from Excel file into a DataFrame
df_housing = pd.read_excel(file_name, sheet_name)
# Create the bar chart
fig = px.bar(df_housing, x='Quintile', y='Percentage', title='In Decemeber 2022, My rent or mortgage costs have increased',
labels={'Percentage': '%', 'Quintile': 'Quintiles'})
fig.update_traces(marker_color = '#66c2a4')
# Update y-axis range
fig.update_yaxes(range=[0, 25])
# Show plot
fig.show()
fig = px.line(title='Rental Price overtime')
# Add Food trace with green color
fig.add_scatter(x=dfn['Date'], y=dfn['Rental Price'], mode='lines', name='Rental Price', line=dict(color='green'))
# Add CPI trace with blue color
fig.add_scatter(x=dfn['Date'], y=dfn['CPI'], mode='lines', name='CPI', line=dict(color='blue'))
fig.show()
fig = px.line(title='House Prices overtime')
# Add Food trace with green color
fig.add_scatter(x=dfn['Date'], y=dfn['House Price'], mode='lines', name='House Price', line=dict(color='green'))
# Add CPI trace with blue color
fig.add_scatter(x=dfn['Date'], y=dfn['CPI'], mode='lines', name='CPI', line=dict(color='blue'))
fig.show()
# Specify the sheet name from which to read data
file_name = "Bars_Insights.xlsx"
sheet_name = '2'
# Read data from Excel file into a DataFrame
df_fuel = pd.read_excel(file_name, sheet_name)
# Plot
fig = px.bar(df_fuel, x='Class', y='Percentage', color='Using less fuel such as gas or electricity in my home\xa0', barmode='stack', title='Fuel',
color_discrete_map={'No': px.colors.sequential.BuGn[3],
'Yes': px.colors.sequential.BuGn[4]})
fig.show()
fig = px.line(title='Gas Inflation overtime')
# Add Food trace with green color
fig.add_scatter(x=dfn['Date'], y=dfn['Gas inflation'], mode='lines', name='Gas inflation', line=dict(color='green'))
# Add CPI trace with blue color
fig.add_scatter(x=dfn['Date'], y=dfn['CPI'], mode='lines', name='CPI', line=dict(color='blue'))
fig.show()
# Specify the sheet name from which to read data
file_name = "Bars_Insights.xlsx"
sheet_name = '3'
# Read data from Excel file into a DataFrame
df_Petrol = pd.read_excel(file_name, sheet_name)
# Plot
fig = px.bar(df_Petrol, x='Class', y='Percentage', color="Cutting back on non-essential journeys in my vehicle\xa0", barmode='stack', title='Petrol usage',
color_discrete_map={'No': px.colors.sequential.BuGn[3],
'Yes': px.colors.sequential.BuGn[4]})
fig.show()
fig = px.line(title='Motor Fuel Inflation overtime')
# Add Food trace with green color
fig.add_scatter(x=dfn['Date'], y=dfn['Motor Fuel Price'], mode='lines', name='Motor Fuel Price', line=dict(color='green'))
# Add CPI trace with blue color
fig.add_scatter(x=dfn['Date'], y=dfn['CPI'], mode='lines', name='CPI', line=dict(color='blue'))
fig.show()
Primary Impact of Food Inflation: Food inflation emerges as the primary area of impact, but it's essential to recognize that the crisis has broader implications beyond just food prices.
Allocation of Budget to Essentials: As individuals allocate more of their budget to essentials like food, they may face difficulties in meeting other basic needs, such as heating their homes or saving for emergencies.
Survey Results: The impact on food costs is evident in the results of the below opinion survey, where working class adults were asked in December 2023 what increased in the cost of living. Food costs impacted the working class the most, followed by gas or electricity costs and then motor fuel costs. Lastly, housing costs seemed to be the least affected.
# Specify the sheet name from which to read data
file_name = "Bars_Insights.xlsx"
sheet_name = '5'
# Read data from Excel file into a DataFrame
df_Intro = pd.read_excel(file_name, sheet_name)
# Define the color scale from darker to lighter blue
color_scale = px.colors.sequential.BuGn
# Creating sidebar plot
fig = px.bar(df_Intro, x="All Adults", y="In December 2023, what increased?", orientation='h', title="In December 2023, what increased in your cost of living?"
, color="All Adults", color_continuous_scale=color_scale)
# Customizing hover text to show values in percentage
fig.update_traces(hovertemplate=" %{x}% of Adults")
fig.update_layout(xaxis_title="Percentage (%)", yaxis_title=None)
fig.show()